{include file="header"}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            {if $item}
            <input type="hidden" name="id" value="{$item.id}">
            {/if}
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>LOGO
                </label>
                <div class="layui-input-block">

                    <button type="button" class="layui-btn" id="file_upload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <br>
                    <input type="hidden" name="logo" value="{$item?$item.logo:''}">
                    {if $item}
                    <img class="img_logo" src="{$item.logo|formatImg}" alt="" style="width: 120px;">
                    {else}
                    <img class="img_logo" src="" alt="" style="width: 120px;">

                    {/if}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>原名称
                </label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$item?$item.title:''}" placeholder="" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>其他名称
                </label>
                <div class="layui-input-block">
                    <input type="text" name="title_other" value="{$item?$item.title_other:''}" placeholder="" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>所在国家
                </label>
                <div class="layui-input-block">
                    <input type="text" name="country" value="{$item?$item.country:''}" placeholder="" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    提交
                </button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer','upload'], function() {
        var upload = layui.upload;
        var form = layui.form,
            layer = layui.layer;

        var uploadInst = upload.render({
            elem: '#file_upload' //绑定元素
            ,url: '{:url("set/upload")}' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code!=200){
                    layer.msg(res.message)
                }else{
                    $('[name="logo"]').val(res.data.path)
                    $(".img_logo").attr("src",res.data.url)
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
        //监听提交
        form.on('submit(add)', function(data) {
            request("POST",'{:url("channel/post")}',data.field,function (res,msg) {
                //发异步，把数据提交给php
                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });

    })
</script>
{include file="footer"}